'use strict';

app.controller('alarmCtrl',function($rootScope, $scope, $http) {
            console.log("alarm");
            $scope.alarmImages = [];
    //获取报警图片接口
            
            // $scope.dt = new Date();

            // $scope.format = "yyyy/MM/dd";

            //  $scope.$watch('dt',function(cur,old){
            //     $scope.curResult=cur.getFullYear()+'-'+(cur.getMonth()+1)+'-'+cur.getDate() ;
            //     $scope.oldResult=old.getFullYear()+'-'+(old.getMonth()+1)+'-'+old.getDate() ;
            //     // console.log(55,curResult,oldResult)
            // });
    $http.get('/api/getAlarmImage').then(function(response){
        console.log("alarm");
        if(response.status==200){
            console.log(response);
            $scope.alarmImages = response.data.image;
            console.log($scope.alarmImages);
             
        }
        else{
            console.log(response.status);
        }
    });

    var onload = function (){
        var year=new Date().getFullYear(); //获取当前年份
             
        var sel1 = document.getElementById ('sel1');//获取select下拉列表
        var sel2 = document.getElementById ('sel2');//获取select下拉列表
        var sel3 = document.getElementById ('sel3');//获取select下拉列表
        var sel4 = document.getElementById ('sel4');//获取select下拉列表
        var sel5 = document.getElementById ('sel5');//获取select下拉列表
        // var sel6 = document.getElementById ('sel6');//获取select下拉列表
        var sel7 = document.getElementById ('sel7');//获取select下拉列表
        var sel8 = document.getElementById ('sel8');//获取select下拉列表
        // var sel9 = document.getElementById ('sel9');//获取select下拉列表
        //对年份的选择的下拉框内容进行设置
        for ( var i = 2010; i < year+3; i++)//循环添加2018到当前年份加3年的每个年份依次添加到下拉列表
        {
           var option = document.createElement ('option');
           option.value = i;
           var txt = document.createTextNode (i);
           option.appendChild (txt);
           sel1.appendChild (option); 
           
        }
        //对月份选择的下拉框内容进行设置
        for( var i = 1; i < 13; i++){
            var option = document.createElement ('option');
            option.value = i;
            var txt = document.createTextNode (i);
            option.appendChild (txt);
            sel2.appendChild (option);
        }
        //对日选择的下拉框内容进行设置
        for( var i = 1; i <= 31; i++){
            var option = document.createElement ('option');
            option.value = i;
            var txt = document.createTextNode (i);
            option.appendChild (txt);
            sel3.appendChild (option);
        }
        for ( var i = 0; i < 24; i++)
        {
           var option = document.createElement ('option');
           option.value = i;
           var txt = document.createTextNode (i);
           option.appendChild (txt);
           sel4.appendChild (option);
        }
        for( var i = 0; i< 60; i++){
            var option = document.createElement ('option');
            option.value = i;
            var txt = document.createTextNode (i);
            option.appendChild (txt);
            sel5.appendChild (option);
        }
        // for( var i = 0; i < 60; i++){
        //     var option = document.createElement ('option');
        //     option.value = i;
        //     var txt = document.createTextNode (i);
        //     option.appendChild (txt);
        //     sel6.appendChild (option);
        // }
         for ( var i = 0; i < 24; i++)
        {
           var option = document.createElement ('option');
           option.value = i;
           var txt = document.createTextNode (i);
           option.appendChild (txt);
           sel7.appendChild (option);
        }
        for( var i = 0; i< 60; i++){
            var option = document.createElement ('option');
            option.value = i;
            var txt = document.createTextNode (i);
            option.appendChild (txt);
            sel8.appendChild (option);
        }
        // for( var i = 0; i < 60; i++){
        //     var option = document.createElement ('option');
        //     option.value = i;
        //     var txt = document.createTextNode (i);
        //     option.appendChild (txt);
        //     sel9.appendChild (option);
        // }

        $scope.year = 0;
        $scope.month = 0;
        $scope.day = 0;
        $scope.hour1 = 0;
        $scope.minute1 = 0;
        $scope.second1 = 0;
        $scope.hour2 = 0;
        $scope.minute2 = 0;
        $scope.second2 = 0;
        // $scope.change = function(data){
        //     // console.log(data);
        //     $scope.year = data;
        // }

        $scope.changeYear = function(data){
            // console.log(data);
            $scope.year = data;
            // console.log($scope.year);
        }
        $scope.changeMonth = function(data){
            // console.log(data);
            $scope.month = data;
            // console.log($scope.month);
        }
        $scope.changeDay = function(data){
            // console.log(data);
            $scope.day = data;
            // console.log($scope.day);
        }
        $scope.changeHour1 = function(data){
            // console.log(data);
            $scope.hour1 = data;
            // console.log($scope.hour1);
        }
        $scope.changeMinute1 = function(data){
            // console.log(data);
            $scope.minute1 = data;
            // console.log($scope.minute1);
        }
        $scope.changeSecond1 = function(data){
            // console.log(data);
            $scope.second1 = data;
            // console.log($scope.second1);
        }
        $scope.changeHour2 = function(data){
            // console.log(data);
            $scope.hour2 = data;
        }
        $scope.changeMinute2 = function(data){
            // console.log(data);
            $scope.minute2 = data;
        }
        $scope.changeSecond2 = function(data){
            // console.log(data);
            $scope.second2 = data;
        }
        
    }

    onload();
    $scope.alarmSubmit = function (){
        var year,month,day,hoursta,minsta,secondsta,hourend,minend,secondend = "";
        year = $scope.year;
        if($scope.month < 10){//如果月份小于10，则显示的时候前面补0
            month = '0' + $scope.month;
        }else{
            month = $scope.month;
        }
        if($scope.day < 10){//如果日份小于10，则显示的时候前面补0
            day = '0' + $scope.day;
        }else{
            day = $scope.day;
        }
        if($scope.hour1<10){
            hoursta = '0' + $scope.hour1;
        }else{
            hoursta = $scope.hour1;
        }
        if($scope.minute1<10){
            minsta = '0' + $scope.minute1;
        }else{
            minsta = $scope.minute1;
        }
        if($scope.second1<10){
            secondsta = '0' + $scope.second1;
        }else{
            secondsta = $scope.second1;
        }
        if($scope.hour2<10){
            hourend = '0' + $scope.hour2;
        }else{
            hourend = $scope.hour2;
        }
        if($scope.minute2<10){
            minend = '0' + $scope.minute2;
        }else{
            minend = $scope.minute2;
        }
        if($scope.second2<10){
            secondend = '0' + $scope.second2;
        }else{
            secondend = $scope.second2;
        }

        $scope.imgTime = {
            "date":"",
            "timeStart":"",
            "timeEnd":""
        };
        //对所选日期格式进行拼接
         $scope.imgTime.date = year + month + day;
        //对所选起始时间进行拼接
         $scope.imgTime.timeStart = hoursta + ':' + minsta + ':' + secondsta;
        //对所选结束时间进行拼接
         $scope.imgTime.timeEnd = hourend + ':' + minend + ':' + secondend;
        console.log($scope.imgTime);
        
        var timeData = $scope.imgTime;
        $http.get('/api/searchAlarmImage',{params:{"date":timeData.date,"timeStart":timeData.timeStart,"timeEnd":timeData.timeEnd}}).then(function(response){
            if(response.status == 200){
                console.log(response);
                $scope.alarmImages = response.data.image;//显示更新后的图片
            }
            else{
              console.log(response.status);
              console.log(response.data);
            }
        });



    }
    
    
    $scope.bigImage = function (url){
    	
    	$scope.fullImage = url;
    	//console.log($scope.fullImage);
    }
  
});